home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / gg / gengetopt-2.6.lha / gengetopt-2.6 / doc / no_getopt_long.txt < prev    next >
Text File  |  2001-12-16  |  2KB  |  59 lines

  1. WHAT IF GETOPT_LONG IS NOT THERE?
  2.  
  3. If you use gengetopt to generate C functions for parsing command line
  4. arguments you have to know that these generated functions use getopt_long
  5. to actually read the command line and parsing it. This function is typically
  6. part of the standard C library, but some libraries may not include it.
  7. But this is not a problem: we provide C files that actually implement
  8. getopt_long function: getopt.c getopt1.c and getopt.h.
  9. You'll find these files in the <prefix>/share/gengetopt directory
  10. where <prefix> is the one you specified during compilation.
  11. If no prefix had been specified, /usr/local is the default.
  12. If you downloaded gengetopt in binary form prefix will probably be
  13. /usr/local or /usr.
  14.  
  15. You can simply compile these files and link them to the executable
  16. of you program. But if you use automake and autoconf here's a more
  17. elegant solution; keep on reading ...
  18.  
  19. This a little explanation on how discovering if getopt_long
  20. is in the standard C library of your C compiler and what to do if it
  21. is not there. This technique can be used if you use automake and autoconf
  22. to build your package's configure script.
  23.  
  24. In configure.in add the following lines:
  25.  
  26. dnl check for getopt in standard library
  27. AC_SUBST(LIBOBJS)
  28. AC_CHECK_FUNCS(getopt_long , , [LIBOBJS="$LIBOBJS getopt.o getopt1.o"] ) 
  29.  
  30. This macro checks if getopt_long function is in C library;
  31. if it is not there it adds getopt.o and getopt1.o to the objects files
  32. that will be linked to your executable (LIBOBJS).
  33. Notice: the AC_SUBST is not necessary if you have already used
  34. a macro such as AC_REPLACE_FUNC.
  35.  
  36. Then in Makefile.am of your source directory you have to add the contents
  37. of LIBOBJS to the LDADD of the program that has to use getopt_long;
  38. e.g. if the program 'foo' has to use getopt_long, you have to add
  39. the following line
  40.  
  41. foo_LDADD = @LIBOBJS@
  42.  
  43. Now these files will be compiled and linked to your program only if
  44. necessary.
  45.  
  46. Moreover you have to add getopt.c getopt1.c and getopt.h to your
  47. distribution. Note that it is not necessary to put these file names
  48. among the foo_SOURCES contents), but you have to add getopt.h to EXTRA_DIST:
  49.  
  50. EXTRA_DIST = getopt.h 
  51.  
  52. You may want to take a look at gengetopt's configure.in and src/Makefile.am:
  53. they both use the techniques described here.
  54.  
  55. I hope you find this document useful :-)
  56.  
  57. Happy Coding!
  58.  
  59.       Lorenzo Bettini <bettini@gnu.org>